package com.ljph.ljaker.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 商品类别
 * Created by yuzhou on 16/9/26.
 */
public enum GoodType {

    MOBILE(1, "手机"),
    CARD(2, "号卡"),
    ACCESSORY(3, "配件"),
    SMART(4, "智能硬件");

    private int type;
    private String label;
    public int getType() {
        return type;
    }
    public String getLabel() {
        return label;
    }

    GoodType(int type, String label){
        this.type = type;
        this.label = label;
    }

    public static GoodType typeOf(int type){
        for(GoodType value : values()) {
            if(value.getType() == type) {
                return value;
            }
        }
        return null;
    }

    public static JSONArray toArray () {

        JSONArray ja = new JSONArray();
        for(GoodType value : values()) {
            JSONObject jo = new JSONObject();
            jo.put("type", value.getType());
            jo.put("label", value.getLabel());
            ja.add(jo);
        }

        return ja;
    }
}
